Clover coverage report - bexee - 0.1
Coverage timestamp: Do Dez 16 2004 13:24:06 CET
file stats: LOC: 77   Methods: 5
NCLOC: 36   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
MemoryProcessContextDAO.java 100% 100% 100% 100%
coverage
 1   
 /*
 2   
  * $Id: MemoryProcessContextDAO.java,v 1.1 2004/12/15 14:18:09 patforna Exp $
 3   
  *
 4   
  * Copyright (c) 2004 Patric Fornasier, Pawel Kowalski
 5   
  * Berne University of Applied Sciences
 6   
  * School of Engineering and Information Technology
 7   
  * All rights reserved.
 8   
  */
 9   
 package bexee.dao;
 10   
 
 11   
 import java.util.HashMap;
 12   
 import java.util.Map;
 13   
 
 14   
 import org.apache.commons.id.serial.AlphanumericGenerator;
 15   
 
 16   
 import bexee.core.ProcessContext;
 17   
 
 18   
 /**
 19   
  * This class uses memory rather than persistent storage to store and load
 20   
  * <code>ProcessContext</code> objects.
 21   
  * 
 22   
  * @version $Revision: 1.1 $, $Date: 2004/12/15 14:18:09 $
 23   
  * @author Patric Fornasier
 24   
  * @author Pawel Kowalski
 25   
  */
 26   
 public class MemoryProcessContextDAO implements ProcessContextDAO {
 27   
 
 28   
     protected static Map map;
 29   
 
 30   
     private static AlphanumericGenerator generator;
 31   
 
 32   
     /**
 33   
      * Creates a new <code>MemoryProcessContextDAO</code> that uses a static
 34   
      * <code>Map</code> to manage the stored <code>ProcessContext</code>
 35   
      * objects.
 36   
      */
 37  10
     public MemoryProcessContextDAO() {
 38  10
         if (map == null) {
 39  4
             map = new HashMap();
 40   
         }
 41  10
         if (generator == null) {
 42  4
             generator = generator = new AlphanumericGenerator(false, 10);
 43   
         }
 44   
     }
 45   
 
 46  2
     public void delete(String id) {
 47  2
         map.remove(id);
 48   
     }
 49   
 
 50  14
     public ProcessContext find(String id) {
 51  14
         return (ProcessContext) map.get(id);
 52   
     }
 53   
 
 54  8
     public String insert(ProcessContext ctx) {
 55   
 
 56   
         // generate id and set it on process context
 57  8
         String id = generator.nextStringIdentifier();
 58  8
         ctx.setId(id);
 59   
 
 60   
         // store process context and return id
 61  8
         map.put(id, ctx);
 62  8
         return id;
 63   
     }
 64   
 
 65  4
     public void update(ProcessContext ctx) throws DAOException {
 66   
 
 67   
         // check if we have that object already
 68  4
         String id = ctx.getId();
 69  4
         ProcessContext oldCtx = find(id);
 70  4
         if (oldCtx == null) {
 71  2
             throw new DAOException("No object with id " + id + "exists");
 72   
         }
 73   
 
 74   
         // replace with new version
 75  2
         map.put(id, ctx);
 76   
     }
 77   
 }